﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ljh.MyControls
{
    public partial class THMeter : UserControl
    {
        #region 字段、属性
        /// <summary>
        /// 白条默认高度（单位像素）
        /// </summary>
        private const int _barHeight = 135;

        /// <summary>
        /// 温湿度值上限
        /// </summary>
        private const double _upperLimit = 70.0;

        /// <summary>
        /// 温湿度值下限
        /// </summary>
        private const double _lowerLimit = 0.0;

        /// <summary>
        /// 温湿度计数值
        /// </summary>
        [Category("扩展")]
        [DefaultValue(_lowerLimit)]
        [Description("此组件的数值，默认0.0")]
        public double SetTHValue
        {
            get
            {
                return _thValue;
            }
            set
            {
                if (value < 0.0 || value > 70.0)
                {
                    MessageBox.Show("温湿度值必须在[0.0, 70.0]之间！", "消息提示");
                }
                else
                {
                    _thValue = value;

                    // 温湿度值对应的实际高度
                    double valueHeight = (_barHeight / _upperLimit) * value;

                    // 实际白条高度（白条默认高度 - 温湿度值对应的实际高度）
                    this.lblBar.Height = _barHeight - Convert.ToInt32(valueHeight);
                }
            }
        }
        private double _thValue = _lowerLimit;

        /// <summary>
        /// 温湿度计背景色
        /// </summary>
        [Category("扩展")]
        [DefaultValue(typeof(BgColor), "BgColor.Green")]
        [Description("此组件的背景色，默认绿色")]
        public BgColor SetBgColor
        {
            get
            {
                return _bgColor;
            }
            set
            {
                _bgColor = value;

                if (_bgColor == BgColor.Red)
                {
                    this.panelBg.BackgroundImage = Properties.Resources.red_all;
                }
                else
                {
                    this.panelBg.BackgroundImage = Properties.Resources.green_all;
                }
            }
        }
        private BgColor _bgColor = BgColor.Green;
        #endregion

        #region 构造方法
        public THMeter()
        {
            InitializeComponent();
        }
        #endregion

        #region 其他方法

        #endregion

        #region 温湿度计颜色枚举
        public enum BgColor
        {
            Red,
            Green
        }
        #endregion
    }
}
